from django.shortcuts import render
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.filters import SearchFilter
from rest_framework.pagination import PageNumberPagination
from rest_framework.viewsets import ModelViewSet

from student.models import Province, Municipality
from student.ser import ProvinceSerializer, MunicipalitySerializer


# Create your views here.
class Page(PageNumberPagination):
    page_size =2
    page_size_query_param = 'size'
    page_query_param = 'page'
class ProvinceViews(ModelViewSet):
    queryset = Province.objects.all()
    serializer_class = ProvinceSerializer
class MunicipalityViews(ModelViewSet):
    queryset = Municipality.objects.all()
    serializer_class = MunicipalitySerializer
    pagination_class = Page
    filter_backends = [DjangoFilterBackend,SearchFilter]
    filterset_fields = ['name','food','status','province']
    search_fields = ['name','food']

    def perform_create(self, Instance):
        Instance.status=1
        Instance.save()


